package com.example.egnotice1.controller;

import com.example.egnotice1.base.response.JsonResult;
import com.example.egnotice1.mapper.NoticeMapper;
import com.example.egnotice1.pojo.dto.AddNoticeParam;
import com.example.egnotice1.pojo.entity.Notice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
@Slf4j
@RestController
@RequestMapping("/v1/notice")
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @PostMapping("/add")
    public JsonResult add(AddNoticeParam addNoticeParam){
        Notice notice=new Notice();
        log.debug("addNoticeParam="+addNoticeParam);
        BeanUtils.copyProperties(addNoticeParam,notice);
        notice.setUserId(1L);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        log.debug("notice:"+notice);
        noticeMapper.insertNotice(notice);
        return JsonResult.ok();
    }
    @GetMapping("/list")
    public JsonResult selectNoticeList(){
        return JsonResult.ok(noticeMapper.selectNoticeList());
    }
}
